//
//  ViewController.m
//  YSFDemo
//
//  Created by amao on 8/25/15.
//  Copyright (c) 2015 Netease. All rights reserved.
//

#import "QYMainViewController.h"
#import "QYLogViewController.h"
#import "QYDetailViewController.h"

#import "QYDemoConfig.h"



@interface QYDetailViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *h1;
@property (strong, nonatomic) IBOutlet UIImageView *h2;
@property (strong, nonatomic) IBOutlet UIImageView *h4;
@property (strong, nonatomic) UIButton *contact;

@end

@implementation QYDetailViewController



-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.index == 1 || self.index == 3) {
        self.navigationItem.title = @"七鱼银票";
        _h1.image = [UIImage imageNamed:@"detail_1"];
    } else {
        self.navigationItem.title = @"七鱼宝";
        _h1.image = [UIImage imageNamed:@"detail_21"];
    }

    _h2.image = [UIImage imageNamed:@"detail_2"];
    _h4.image = [UIImage imageNamed:@"detail_3"];
    
    _contact = [[UIButton alloc] initWithFrame:CGRectZero];
    [_contact setImage:[UIImage imageNamed:@"button_contact"] forState:UIControlStateNormal];
    [_contact sizeToFit];
    [_h4 addSubview:_contact];
    
    [_contact addTarget:self action:@selector(onContact:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)viewDidLayoutSubviews
{

}

#pragma mark - 事件处理
- (IBAction)onContact:(id)sender {
    if (self.index == 3 || self.index == 4) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"输入客服分配参数" message:nil preferredStyle:UIAlertControllerStyleAlert];
        [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            textField.placeholder = @"请输入客服分组ID";
        }];
        [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            textField.placeholder = @"请输入客服ID";
        }];
        [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            textField.placeholder = @"请输入机器人ID";
        }];
        [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            textField.placeholder = @"请输入常见问题模板ID";
        }];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:cancelAction];
        KStrongSelf
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (alert.textFields.count == 4) {
                UITextField *field_1 = [alert.textFields objectAtIndex:0];
                UITextField *field_2 = [alert.textFields objectAtIndex:1];
                UITextField *field_3 = [alert.textFields objectAtIndex:2];
                UITextField *field_4 = [alert.textFields objectAtIndex:3];
                int64_t groupId = field_1.text.length ? [field_1.text longLongValue] : 0;
                int64_t staffId = field_2.text.length ? [field_2.text longLongValue] : 0;
                int64_t robotId = field_3.text.length ? [field_3.text longLongValue] : 0;
                int64_t templateId = field_4.text.length ? [field_4.text longLongValue] : 0;
                
                [strongSelf onChatWithGroupId:groupId staffId:staffId robotId:robotId templateId:templateId];
            }
        }];
        [alert addAction:okAction];
        [self presentViewController:alert animated:YES completion:nil];
    } else {
        [self onChatWithGroupId:0 staffId:0 robotId:0 templateId:0];
    }
}

- (void)onChatWithGroupId:(int64_t)groupId staffId:(int64_t)staffId robotId:(int64_t)robotId templateId:(int64_t)templateId {
    if ([QYDemoConfig sharedConfig].isFusion) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:kQYInvalidAccountTitle
                                                                       message:kQYInvalidAccountMessage
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alert animated:YES completion:nil];
        return;
    }
    
    NSString *title;
    NSString *pageUrl;
    if (self.index == 1 || self.index == 3) {
        title = @"七鱼银票";
        pageUrl = @"https://8.163.com/billList.htm";
    } else {
        title = @"七鱼宝";
        pageUrl = @"https://8.163.com/dqlc/dqlcList.htm";
    }

}

@end
